package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class EqualsIterator {
	@SuppressWarnings("unchecked")
	public static <T> boolean equalsIters(Iterator<T> it1, Iterator<T> it2) {
		List list1 = new ArrayList();
		List list2 = new ArrayList();

		while (it1.hasNext()) {
			list1.add(it1.next());
		}

		while (it2.hasNext()) {
			list2.add(it2.next());
		}

		return equalsLists(list1, list2);
	}

	public static <T> boolean equalsLists(List list1, List list2) {
		if (list1.size() != list2.size()) {
			return false;
		}

		for (int i = 0; i < list1.size(); ++i) {
			if (!equals(list1.get(i), list2.get(i))) {
				return false;
			}
		}

		return true;
	}

	public static boolean equals(Object a, Object b) {
		if (a == null) {
			return b == null;
		}

		return a.equals(b);
	}
}
